package temp.lho.lws.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import temp.lho.lws.emum.MsgStatusEmum;
import temp.lho.lws.pojo.HumanInjuryInfo;
import temp.lho.lws.result.ResultBody;
import temp.lho.lws.service.IHumanInjuryInfoService;
import temp.lho.lws.vo.LayuiResult;

import java.util.List;

/**
 * (HumanInjuryInfo)表控制层
 *
 * @author makejava
 * @since 2020-07-06 23:08:54
 */
@RestController
@RequestMapping("/humanInjuryInfo")
public class HumanInjuryInfoController {
    /**
     * 服务对象
     */
    @Autowired
    private IHumanInjuryInfoService humanInjuryInfoService;


    @PostMapping("/addHuman")
    public ResultBody addHuman(@RequestBody HumanInjuryInfo humanInjuryInfo) {
        int add = humanInjuryInfoService.add(humanInjuryInfo);
        return add > 0 ?
                ResultBody.toResultBody(MsgStatusEmum.ADD_SUCCESS.getCode(),
                        MsgStatusEmum.ADD_SUCCESS.getMsg()):
                ResultBody.toResultBody(MsgStatusEmum.ADD_ERROR.getCode(),
                        MsgStatusEmum.ADD_ERROR.getMsg());
    }

    @GetMapping("/findByClaimmainid/{claimmainid}")
    public LayuiResult findByClaimmainid(@PathVariable Integer claimmainid) {
        List<HumanInjuryInfo> byClaimmainid = humanInjuryInfoService.findByClaimmainid(claimmainid);
        if (byClaimmainid != null && byClaimmainid.size() != 0) {
            return new LayuiResult(0,"",byClaimmainid.size(),byClaimmainid);
        } else {
            return new LayuiResult(0,"",0,null);
        }
    }

    @GetMapping("/deleteHuman")
    public ResultBody deleteHuman(Integer humaninjuryid) {
        int delete = humanInjuryInfoService.delete(humaninjuryid);
        return delete > 0 ?
                ResultBody.toResultBody(MsgStatusEmum.DELETE_SUCCESS.getCode(),
                        MsgStatusEmum.DELETE_SUCCESS.getMsg())
                :ResultBody.toResultBody(MsgStatusEmum.DELETE_ERROR.getCode(),
                MsgStatusEmum.DELETE_ERROR.getMsg());
    }

}